package com.ruoyi.web.controller.clothing;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.clothing.domain.SysOrderGoods;
import com.ruoyi.clothing.service.ISysOrderGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单管理Controller
 *
 * @author weh
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/clothing/order_goods")
public class SysOrderGoodsController extends BaseController
{
    @Autowired
    private ISysOrderGoodsService sysOrderGoodsService;

    /**
     * 查询订单管理列表
     */
//    @PreAuthorize("@ss.hasPermi('clothing:order_goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysOrderGoods sysOrderGoods)
    {
        startPage();
        List<SysOrderGoods> list = sysOrderGoodsService.selectSysOrderGoodsList(sysOrderGoods);
        return getDataTable(list);
    }

    /**
     * 导出订单管理列表
     */
//    @PreAuthorize("@ss.hasPermi('clothing:order_goods:export')")
    @Log(title = "订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOrderGoods sysOrderGoods)
    {
        List<SysOrderGoods> list = sysOrderGoodsService.selectSysOrderGoodsList(sysOrderGoods);
        ExcelUtil<SysOrderGoods> util = new ExcelUtil<SysOrderGoods>(SysOrderGoods.class);
        util.exportExcel(response, list, "订单管理数据");
    }

    /**
     * 获取订单管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('clothing:order_goods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(sysOrderGoodsService.selectSysOrderGoodsById(id));
    }

    /**
     * 新增订单管理
     */
//    @PreAuthorize("@ss.hasPermi('clothing:order_goods:add')")
    @Log(title = "订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysOrderGoods sysOrderGoods)
    {
        return toAjax(sysOrderGoodsService.insertSysOrderGoods(sysOrderGoods));
    }

    /**
     * 修改订单管理
     */
//    @PreAuthorize("@ss.hasPermi('clothing:order_goods:edit')")
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysOrderGoods sysOrderGoods)
    {
        return toAjax(sysOrderGoodsService.updateSysOrderGoods(sysOrderGoods));
    }

    /**
     * 删除订单管理
     */
//    @PreAuthorize("@ss.hasPermi('clothing:order_goods:remove')")
    @Log(title = "订单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(sysOrderGoodsService.deleteSysOrderGoodsByIds(ids));
    }

    /**
     *立即下单
     * @param data 对象
     * @return 结果
     */
    @PostMapping("/place_order")
    public AjaxResult placeOrder(@RequestBody SysOrderGoods data){
        return toAjax(sysOrderGoodsService.placeOrder(data));
    }

    /**
     * 根据状态查询不同的列表
     * @param status 状态
     * @return 结果
     */
    @GetMapping("/selectOrderByStatus")
    public List<SysOrderGoods> selectOrderGoodsByStatus(@RequestParam Integer status){
        return sysOrderGoodsService.selectOrderGoodsByStatus(status);
    }

    /**
     * 根据id返回订单信息
     * @param id 用户id
     * @return 结果
     */
    @GetMapping("/selectOrderGoodsById/{id}")
    public List<SysOrderGoods> selectOrderGoodsById(@PathVariable("id") Integer id){
        System.out.println("查询订单");
        return sysOrderGoodsService.selectOrderGoodsById(id);
    }

    /**
     * 删除订单
     * @param id
     * @return
     */
    @DeleteMapping("/deleteOrderGoodsById")
    public AjaxResult deleteOrderGoodsById(@RequestParam Integer id){
        sysOrderGoodsService.deleteOrderGoodsById(id);
        return AjaxResult.success("删除成功");
    }

}
